package com.example.socialwebserver.controller;

import com.example.socialwebserver.pojo.*;
import com.example.socialwebserver.service.ActivityService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;
import java.util.List;

@RestController
@CrossOrigin
public class ActivityController {
    @Autowired
    ActivityService activityService;

    @RequestMapping("/activity/createActivity")
    public ServerResult createActivity(ActivityCreateDTO activityCreateDTO)
    {
        boolean res = activityService.createActivity(activityCreateDTO);
        ServerResult serverResult;
        if(res)
        {
            serverResult = new ServerResult(0, "活动发起成功", null);
        }
        else
        {
            serverResult = new ServerResult(100, "活动创建失败", null);
        }
        return serverResult;

    }

    @RequestMapping("/activity/updateActivity")
    public ServerResult updateActivity(ActivityUpdateDTO activityUpdateDTO)
    {
        boolean res = activityService.updateActivity(activityUpdateDTO);
        ServerResult serverResult;
        if(res)
        {
            serverResult = new ServerResult(0, "活动信息修改成功", null);
        }
        else
        {
            serverResult = new ServerResult(100, "活动信息修改失败", null);
        }
        return serverResult;
    }

    @RequestMapping("/activity/joinActivity")
    public ServerResult joinActivity(ActivityJoinDAO activityJoinDTO)
    {
        boolean res = activityService.joinActivity(activityJoinDTO);
        ServerResult serverResult;
        if(res)
        {
            serverResult = new ServerResult(0, "加入活动成功", null);
        }
        else
        {
            serverResult = new ServerResult(100, "加入活动失败", null);
        }
        return serverResult;
    }

    @RequestMapping("/activity/quitActivity")
    public ServerResult quitActivity(ActivityJoinDAO activityJoinDAO)
    {
        boolean res = activityService.quitActivity(activityJoinDAO);
        ServerResult serverResult;
        if(res)
        {
            serverResult = new ServerResult(0, "退出活动成功", null);
        }
        else
        {
            serverResult = new ServerResult(100, "退出活动失败", null);
        }
        return serverResult;
    }

    @RequestMapping("/activity/selectByClassId")
    public ServerResult selectByClassId(Integer categoryId)
    {
        List<ActivityVO> activityVOS = activityService.selectByClassId(categoryId);
        ServerResult serverResult = new ServerResult(0, "分类查询活动", activityVOS);
        return serverResult;
    }

    @RequestMapping("/activity/selectAll")
    public ServerResult selectAll()
    {
        List<ActivityVO> activityVOS = activityService.selectAll();
        ServerResult serverResult = new ServerResult(0, "显示所有活动", activityVOS);
        return serverResult;
    }

    @RequestMapping("/activity/selectById")
    public ServerResult selectById(Integer activityId)
    {
        ActivityVO activityVO = activityService.selectById(activityId);
        return new ServerResult(0,"活动信息",activityVO);
    }

    @RequestMapping("/activity/deleteActivity")
    public ServerResult deleteActivity(Integer activityId)
    {
        boolean res = activityService.deleteActivity(activityId);
        ServerResult serverResult;
        if(res)
        {
            serverResult = new ServerResult(0, "删除活动成功", null);
        }
        else
        {
            serverResult = new ServerResult(101, "删除活动失败", null);
        }
        return serverResult;
    }
}
